package com.hs.android.fortress.ingame;

import android.util.Log;

import com.google.android.gms.maps.model.LatLng;

public class calculateDistance {

	private static final float G = 9.8f;
	
	private float mBombWeight;
	private float mBombPower;
	private float mBombDegree;
	private float mAzimuth;
	private LatLng mLocation;
	
	
	
	public calculateDistance(double mBombWeight, float mBombPower, float mBombDegree, float mAzimuth) {
		this.mBombWeight=(float)mBombWeight;
		this.mBombPower=(float) (mBombPower*14.7);
		this.mBombDegree=95-mBombDegree;
		this.mAzimuth=mAzimuth;
	}
	
	public void setmLocation(LatLng mLocation){
		this.mLocation=mLocation;
	}
	
	public float calDistance(){
		
		float distance;
		float v=2*mBombPower/mBombWeight;
		distance=(float) (2*v*(Math.cos(Math.toRadians(mBombDegree)))*(Math.sin(Math.toRadians(mBombDegree)))/G);
		
		return distance;
		
		
		
	}
	
	public LatLng calLocation(){
		LatLng hitLocation = null;
		float distanceLat=0, distanceLng=0;
		
		distanceLat=(float)((calDistance()*Math.cos(Math.toRadians(mAzimuth))))/111111;
		distanceLng=(float)((calDistance()*Math.sin(Math.toRadians(mAzimuth))))/88800;
		//(1- (calDistance()*Math.sin(Math.toRadians(mAzimuth))))
		//Log.d("Azimuth","sin : "+(1-Math.sin(mAzimuth))+" cos :"+(1+Math.cos(mAzimuth)));
		/*
		if(mAzimuth>=0 && mAzimuth<90){
			
		}else if(mAzimuth>=90 && mAzimuth<180){
			distanceLng=-distanceLng;
		}else if(mAzimuth>=180 && mAzimuth<270){
			distanceLat=-distanceLat;
			distanceLng=-distanceLng;
		}else{
			distanceLat=-distanceLat;
		}
		*/
		distanceLat=(float)mLocation.latitude+distanceLat;
		distanceLng=(float)mLocation.longitude+distanceLng;
		
		Log.d("Azimuth","Azimuth : "+mAzimuth);
		Log.d("Distance","distanceLat : "+distanceLat+"distanceLng : "+distanceLng);
		hitLocation=new LatLng(distanceLat, distanceLng);
		return hitLocation;
	}
}
